{% load humanize %}
{% load task_tags %}
{% load tagging_tags %}
{% load i18n %}
{% load deliverable_tags %}
{% load markup %}

<div class="tasks">
       <div class="task">
       {% if task_list %}
         {% for task in task_list %}
	      <h1>{{ task.title }}</h1>
	      
	      {% if task.is_overdue %}
	        <p>This task is <span class="warning">overdue</span></p>
	      {% endif %}
	      {% if not task.is_overdue and not task.completed_date %}
	        <p>This task is incomplete</p>
	      {% endif %}
	      {% if task.completed_date %}
	        <p>This task is <span class="well-done">complete</span></p>
	      {% endif %}
	      
	      
	    <p>
	      <a href="{% url task_edit task_id=task.id %}">Edit</a>
	      <a href="{% url request_task_update task_id=task.id %}">Request Update</a>
	    </p>
	      

	      {{ task.description|markdown }}

		<table>
          <tr><th>Owner</th><td><a href="{% url person_detail object_id=task.lead.id%}">{{ task.lead }}</a></td></tr>
		  <tr><th>Start Date</th><td>{{ task.start_date }}</td></tr>
		  <tr><th>Due Date</th><td>{{ task.target_date }}</td></tr>
		  <tr><th>Time Estimate (Minutes)</th><td>{{ task.estimate }}</td></tr>
		  <tr>
		    <th>Completed Date</th>
		    <td>
		      {{ task.completed_date }}
		      {% if task.completed_date %}
		      <form action="{% url task_set_complete task_id=task.id %}" method="post">
			<input type="hidden" name="status" value="incomplete" />
			<input type="submit" value="Incomplete" />
		      </form>
		      {% endif %}
		      {% if not task.completed_date %}
		      <form action="{% url task_set_complete task_id=task.id %}" method="post">
			<input type="hidden" name="status" value="complete" />
			<input type="submit" value="Complete" />
		      </form>
		      {% endif %}
		  </td>
		  </tr>
		  {% if task.parent %}
		    <tr><th>Parent Task</th><td><a href="{%url task_detail object_id=task.parent.id %}">{{ task.parent }}</a></td></tr>
		  {% else %}
		    <tr><th>Parent Task</th><td>None</td></tr>
		  {% endif %}

                  {% for deliverable in task.deliverable_set.all %}
	            <tr><th>Deliverable</th><td>{% extended_deliverable_name deliverable %}</td></tr>
                  {% endfor %}  

                  {% for objective in task.objective_set.all %}
                    <tr><th>Objective</th><td><a href="{% url objective_detail object_id=objective.id %}">{{ objective }}</a></td></tr>
                  {% endfor %}

		</table>
            </div>
            
	    <h2>Incomplete Subtasks</h2>
	    {% list_incomplete_subtasks task %}
            <p>
	      <a href="{% url task_add_subTask parent_id=task.id %}">Add a Subtask</a>
	    </p>

	    <h2>Completed Subtasks</h2>
	    {% list_complete_subtasks task %}

        </div>
        {% endfor %}
        {% endif %}
</div>
